<template>
  <div class="panel loveList">
    <div class="tit">
      <span class="left">猜你喜欢</span>
      <span class="right" @click="refresh">
        <i class="icon icon-refresh" :class="{'animation-rotate':animationRotate == true}"></i>
        换一换
      </span>
    </div>
    <ul>
      <li @click="setLabel(item.name)" v-for="item in loveList" :key="item.id">{{item.name}}</li>
    </ul>
    <div class="panel-loading" v-show="!loveList.length">
      <loading></loading>
    </div>
  </div>
</template>

<script>
  import server from '@/api/server/index';
  import { Toast } from 'mint-ui';
  import loading from '@/components/loading/loading';
  export default {
    name: '',
    data() {
      return {
        animationRotate: false,
        loveList: []
      }
    },
    mounted (){
      setTimeout(()=>{
        this. __getLoveList();
      },20);
    },
    methods: {
      setLabel(v) {
        this.$parent.setLabel(v);
      },
      refresh() {
        this.__getLoveList();
      },
      __getLoveList() {
        if(this.animationRotate) return;
        this.animationRotate = true;
        server.searchLoveList().then((rs) => {
          setTimeout(()=> {
            this.animationRotate = false;
          },510);
          this.loveList = rs.loveList;

        }).catch((ms) => {
          Toast(ms);
          this.animationRotate = false;
        });
      }
    },
    components: {
      loading
    }
  }
</script>

<style lang="less">

</style>
